package com.logicalthinking.socialmall.controller.app;

import com.github.chenlijia1111.commonModule.common.requestVo.order.BatchShipParams;
import com.github.chenlijia1111.commonModule.common.requestVo.order.OrderAddParams;
import com.github.chenlijia1111.commonModule.common.requestVo.order.ShipParams;
import com.github.chenlijia1111.utils.common.Result;
import com.logicalthinking.socialmall.biz.OrderBiz;
import com.logicalthinking.socialmall.common.vo.requestVo.order.SocialOrderAddParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单
 *
 * @author Chen LiJia
 * @since 2020/2/19
 */
@RestController
@RequestMapping(value = "app/order")
@Api(tags = "订单")
public class OrderController {

    @Autowired
    private OrderBiz biz;

    @PostMapping(value = "addOrder")
    @ApiOperation(value = "下单")
    public Result addOrder(@RequestBody SocialOrderAddParams params) {
        return biz.addOrder(params);
    }


    /**
     * 试算订单金额
     *
     * @param params 1
     * @return com.github.chenlijia1111.utils.common.Result
     * @since 下午 4:20 2019/11/22 0022
     **/
    @PostMapping(value = "calculatePrice")
    @ApiOperation(value = "试算订单金额")
    public Result calculatePrice(@RequestBody OrderAddParams params) {
        return biz.calculatePrice(params);
    }

    /**
     * 客户取消订单
     * 客户主动取消订单,只能是待支付的订单
     * 并且是组订单全部取消
     *
     * @param groupId 1
     * @return com.github.chenlijia1111.utils.common.Result
     * @since 下午 5:51 2019/11/22 0022
     **/
    @PostMapping(value = "customCancelOrder")
    @ApiOperation(value = "客户取消订单")
    public Result customCancelOrder(String groupId) {
        return biz.customCancelOrder(groupId);
    }

    /**
     * 商家发货
     *
     * @param params
     * @return com.github.chenlijia1111.utils.common.Result
     * @since 下午 5:51 2019/11/22 0022
     **/
    @PostMapping(value = "shopSendExpress")
    @ApiOperation(value = "商家发货")
    public Result shopSendExpress(ShipParams params) {
        return biz.shopSendExpress(params);
    }

    /**
     * 商家批量发货
     *
     * @param params
     * @return com.github.chenlijia1111.utils.common.Result
     * @since 下午 5:51 2019/11/22 0022
     **/
    @PostMapping(value = "shopSendExpress/batch")
    @ApiOperation(value = "商家批量发货")
    public Result shopBatchSendExpress(BatchShipParams params) {
        return biz.shopBatchSendExpress(params);
    }

    /**
     * 客户收货
     *
     * @param orderNo 订单编号
     * @return com.github.chenlijia1111.utils.common.Result
     * @since 下午 5:51 2019/11/22 0022
     **/
    @PostMapping(value = "customReceiveExpress")
    @ApiOperation(value = "客户收货")
    public Result customReceiveExpress(String orderNo) {
        return biz.customReceiveExpress(orderNo);
    }


    /**
     * 支付回调
     * 只处理关于普通订单的回调业务,不处理其他不相关业务(拼团、秒杀)
     *
     * 注意处理访问权限
     *
     * @param payRecode     商家支付订单号
     * @param transactionId 第三方支付交易流水号
     * @param payChannel    支付渠道
     * @return void
     * @since 上午 9:57 2019/11/27 0027
     **/
    @PostMapping(value = "payNotify")
    @ApiOperation(value = "支付回调")
    public void payNotify(String payRecode, String transactionId, String payChannel) {
        biz.payNotify(payRecode, transactionId, payChannel);
    }

}
